# -*- coding: utf-8 -*-
# @File : 01multi_thread_craw.py
# @Time : 2024/6/18 15:47
# @Author : syq
# @Email : 1721169065@qq.com
# @Software: PyCharm
import time

import blog_spider
import threading
#定义一个单线程函数
def single_thread():
    print("single_thread begin")
    for url in blog_spider.urls:
        blog_spider.craw(url)
    print("single_thread end")
#定义一个多线程函数
def multi_thread():
    print("multi_thread begin")
    threads=[]
    for url in blog_spider.urls:
        threads.append(
            threading.Thread(target=blog_spider.craw,args=(url,))
        )
    for thread in threads:
        thread.start()
    for thread in threads:
        thread.join()
    print("multi_thread end")
if __name__ == '__main__':
    start=time.time()
    single_thread()
    end=time.time()
    print("single_thread单线程函数运行的时间为：", end-start,"秒")
    start = time.time()
    multi_thread()
    end = time.time()
    print("multi_thread多线程函数运行的时间为：", end - start, "秒")